package com.project.servlet;

import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
@Controller
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String path=req.getServletPath();
        path=path.substring(1,path.lastIndexOf("."));
        Class c = StudentController.class;
        try {

            Object stuObj=c.getConstructor().newInstance();
            Method m = c.getMethod(path,HttpServletRequest.class,HttpServletResponse.class);
            m.invoke(stuObj,req,resp);

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
